import org.apache.hc.client5.http.classic.HttpClient;
import org.apache.hc.client5.http.classic.methods.HttpGet;
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
import org.apache.hc.client5.http.impl.classic.HttpClients;
import org.apache.hc.core5.http.io.entity.EntityUtils;


public class HttpClientExample {
    public static void main(String[] args) {
        //    1.创造Httplicent对象
         CloseableHttpClient aDefault = HttpClients.createDefault();
//         2.创建HttpGet对象，设置url访问地址
         HttpGet httpGet = new HttpGet("http://www.itcast.cn");
      CloseableHttpResponse response=null;
        try {
             response=aDefault.execute(httpGet);
            if ( response.getStatusLine().getStatusCode()==200) {
               String content= EntityUtils.toString(response.getEntity(),"utf8");
                System.out.println();

            }
        } catch (java.io.IOException e) {
        }finally {
            response.close();

        }
    }
}
